import os
import sys

script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(script_path)
sys.path.insert(0, script_dir)

import pygame
from typing import List, Union
from other import *
from amount import *
from base import *


# 植物
class Plant(pygame.sprite.Sprite):

    sign = "Plant-sign"

    def __init__(
        self, BVolume: Life, KSpeed: MSpeed, Damage: Damage, Type: int
    ) -> None:
        super().__init__()
        self.BVolume: Life = BVolume
        """植物血量"""
        self.KSpeed: MSpeed = KSpeed
        """植物攻击速度"""
        self.Damage: Damage = Damage
        """植物攻击力"""
        self.Type: int = Type
        """植物类型"""
        self.rect: pygame.Rect

        self.image: pygame.Surface

    def __str__(self) -> str:
        return "Plant"

    def __add__(self, other):
        if isinstance(other, Damage):
            self.Damage += other.value
        elif isinstance(other, Life):
            self.BVolume += other.value

    def __sub__(self, other: pygame.sprite.Sprite):
        if isinstance(other, Damage):
            self.Damage -= other.value
        elif isinstance(other, Life):
            self.BVolume -= other.value


class pot(pygame.sprite.Sprite):
    def __init__(self, screen: pygame.Surface) -> None:
        self.BVolume = 0
        self.screen: pygame.Surface = screen
        self.gif_frame = gif_frame(screen)
        self.plantingTarget: List[pygame.sprite.Sprite] = []


# 小推车
class Car:
    def __init__(self) -> None:
        self.MSpeed = 0  # 移动速度
        self.APower = 99999

    def action(self):
        """行动"""
        self.killTarget: List[Union[Plant, pygame.sprite.Sprite]] = [Plant]

    def __str__(self):
        return "小推车"

    def __add__(self, other):
        if isinstance(other, Damage):
            self.APower += other.value
        elif isinstance(other, Life):
            self.BVolume += other.value

    def __sub__(self, other):
        if isinstance(other, Damage):
            self.APower -= other.value
        elif isinstance(other, Life):
            self.BVolume -= other.value
